package itea.bignews.dwr;

import itea.bignews.sys.ClientConfig;

import java.util.Date;

import static itea.bignews.sys.Static.currentDate;
import static itea.bignews.sys.Static.strb;

/**
 * Server Result
 * @version $Id: SResult.java 52 2009-09-11 09:32:44Z iteahere $
 * @author itea
 * @date 2009-8-6
 */
public class SResult {

	public static final String SUCCEED = "OK";
	
	public static final String FAILED = "FAILED";
	
	private String msg;
	
	private Object result;
	
	private Date serverTime;

	private ClientConfig clientConfig;
	
	public SResult() {
		this.serverTime = currentDate();
	}
	
	public SResult(Object result) {
		this.result = result;
		this.serverTime = currentDate();
	}
	
	public SResult(ClientConfig cn, Object result) {
		this.result = result;
		this.clientConfig = cn;
		this.serverTime = currentDate();
	}

	@Override
	public String toString() {
		return strb("SResult {serverTime: ", serverTime, ", msg: ", msg, ", result: ", result, "}").toString();
	}
	
	public static SResult msg(String msg) {
		return new SResult().setMsg(msg);
	}
	
	public static SResult SUCCEED() {
		return new SResult().setMsg(SUCCEED);
	}

	public static SResult FAILED() {
		return new SResult().setMsg(FAILED);
	}
	
	public String getMsg() {
		return msg;
	}

	public SResult setMsg(String msg) {
		this.msg = msg;
		return this;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public Date getServerTime() {
		return serverTime;
	}

	public void setServerTime(Date serverTime) {
		this.serverTime = serverTime;
	}

	public ClientConfig getClientConfig() {
		return clientConfig;
	}

	public void setClientConfig(ClientConfig clientConfig) {
		this.clientConfig = clientConfig;
	}

}
